package com.spm.librarianmanagersystem.controller;

import com.spm.librarianmanagersystem.service.UserInfoService;
import com.spm.librarianmanagersystem.utils.JsonResult;
import com.spm.librarianmanagersystem.utils.UserContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CloseController {
    @Autowired
    private UserInfoService uis;

    @DeleteMapping("/api/user/close")
    public JsonResult<Object> userClose() {
        String currentUserId = UserContextHolder.getCurrentUserId();
        try {
            Boolean aBoolean = uis.userClose(currentUserId);
            UserContextHolder.clearCurrentUserId();
            return new JsonResult<>(aBoolean);
        } catch (Exception e) {
            return new JsonResult<>(1, e.getMessage());
        }
    }
}
